﻿@model IEnumerable<com.fmtx.Model.Article>
@{
    ViewBag.Title = "Index";
}
@using fmtx.Utility;
<div class="widget stacked widget-table action-table">

    <div class="widget-header">
        <i class="icon-th-list"></i>
        <h3>游记信息 </h3>
        <div style="float:right;margin-right:10px;">
           <form class="form-inline" style="margin:0;">
                标题：<input type="text" name="title" class="input-small" placeholder="标题" value="@Request.QueryString["title"]" />
               城市：<input type="text" name="city" class="input-small" placeholder="请选择城市" value="@Request.QueryString["city"]" />
               <input type="hidden" name="cityid" value="@Request.QueryString["cityid"]" />
               景点：<input type="text" name="place" class="input-small" placeholder="请选择景点" value="@Request.QueryString["place"]" />
               <input type="hidden" name="placeid" value="@Request.QueryString["placeid"]" />
               作者：<input type="text" name="uname" class="input-small" placeholder="请选择用户" value="@Request.QueryString["uname"]" />
               <input type="hidden" name="uid" value="@Request.QueryString["uid"]" />
               状态： <select name="statu" class="input-small" >
                   <option value="@com.fmtx.Model.Approved.AllStatu" > </option>
                   <option value="@com.fmtx.Model.Approved.IsPass" >通过审核</option>
                   <option value="@com.fmtx.Model.Approved.Verifying" >审核中</option>
                   <option value="@com.fmtx.Model.Approved.NoPass" >不通过</option>
               </select>
               <button class="btn btn-small" ><i class="btn-icon-only icon-search" style="margin-left:0px;" ></i>搜索</button>
           </form>
        </div>
    </div>
    <!-- /widget-header -->
    <div class="widget-content">
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>#</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>地址</th>
                    <th>景点标签</th>
                    <th>所属用户</th>
                    <th>简介</th>
                    <th>时间</th>
                    <th style="width:6%" >状态</th>
                    <th class="td-actions"></th>
                </tr>
            </thead>
            <tbody>
            @if(Model!=null){
                foreach (var item in Model)
                {
                    <tr id="tr_@item.Id">
                        <td>@item.Id</td>
                        <td ><img src="@StaticCs.ImageUrl/img/OnlyCache?m=OverCut&w=50&h=30&file=@item.FrontCover" /></td>
                        <td title="@item.Title"><a target="_blank" href="/article/@item.Id">@item.Title.RemoveHtml(10)</a></td>
                        <td>@item.Address</td>
                        <td>@item.PlaceTag</td>
                        <td>@item.Uid</td>
                        <td data-placement="left" title="@item.Summary" >@item.Summary.RemoveHtml(20)</td>
                        <td>@item.InTime.ToLocalTime().ToString("yyyy-MM-dd")</td>
                        <td >
                            <div class="dropdown">
                            <a id="statu_@item.Id" href="#" class="dropdown-toggle" data-toggle="dropdown">
                                @switch (item.Statu)
                                {
                                    case com.fmtx.Model.Approved.Verifying:
                                        <text>审核中</text>
                                        break;
                                    case com.fmtx.Model.Approved.IsPass:
                                        <text>审核通过</text>
                                        break;
                                    case com.fmtx.Model.Approved.NoPass:
                                        <text>不通过</text>
                                        break;
                                    case com.fmtx.Model.Approved.AllStatu:
                                        break;
                                    default:
                                        break;
                                }
                            </a>
                             <ul class="dropdown-menu bottom-up pull-left">
                                <li><a onclick="ChangeStatu(@item.Id,'IsPass',this)" href="javascript:;">通过审核</a></li>
                                <li><a onclick="ChangeStatu(@item.Id,'Verifying',this)" href="javascript:;">审核中</a></li>
                                <li><a onclick="ChangeStatu(@item.Id,'NoPass',this)" href="javascript:;">不通过</a></li>
                            </ul>
                           </div>
                        </td>
                        <td class="td-actions">
                            <a title="编辑" href="/admin/article/edit/@item.Id" class="btn btn-small btn-warning">
                                <i class="btn-icon-only icon-edit"></i>
                            </a>
                            <a title="删除"  onclick="DeleteArticle(@item.Id)" class="btn btn-small">
                                <i class="btn-icon-only icon-remove"></i>
                            </a>
                        </td>
                    </tr>
                }
            } 
            </tbody>
        </table>
       <div class="pagination pagination-right"  > <ul id="Pager"></ul></div>
    </div>
    <!-- /widget-content -->

</div>
@section scripts{
    <script type="text/javascript">
        function initPagination() {
            var num_entries = parseInt("@ViewBag.count");
            $("#Pager").pagination(num_entries, {
                link_to: "/admin/article/?index=__id__",
                current_page: parseInt("@(Request.QueryString["index"]??"0")"),
                items_per_page: 12,
                prev_text: '上一页',
                next_text: '下一页 ',
                first_text: "首页",
                last_text: "尾页"
            });
        }
        $(document).ready(function () {
            initPagination();
            $("select[name=statu] option[value=@Request.QueryString["statu"]]").attr("selected",true);
        });

        function ChangeStatu(id,statu,obj)
        {
            $.post("/action/Article/ChangeStatu", { id: id, statu: statu }, function (data) {
                if (data.error == 0) {
                    showinfo("修改成功！");
                    $("#statu_" + id).text($(obj).text());
                } else if (data.error == 1001) {
                    showloginDialog();
                } else {
                    showerror("修改失败！");
                }
            });
        }

        function DeleteArticle(id)
        {
            setconfirm("确定要删除吗？", function () {
                $.post("/action/article/DeleteArticle/", {id:id}, function (data) {
                    if (data.error == 0) {
                        $("#tr_" + id).remove();
                    } else if (data.error == 1001) {
                        showloginDialog();
                    } else {
                        showerror("删除失败！");
                    }
                });
            });
        }
    </script>
    }